package Chapter04.TS;

import java.util.InputMismatchException;
import java.util.Scanner;

public class TestThree {
    /*
     2023-5-26 异常处理
                1->if else 语句跳过异常区域，或者可能出错的区域
                2->try{
                }catch{
                } finally{
                }语句，来判断是否异常，若有则在Catch{......代码块}中解决，随后在finally{......代码块}正常执行
     */


    public static void main(String[] args) {
        Scanner scanner =new Scanner(System.in);
        int a=0;
        int b=0;
        try {
            System.out.print("请输入被除数:");
            a=scanner.nextInt();
            System.out.print("请输入除数:");
            b=scanner.nextInt();
            num(a,b);



        }catch (InputMismatchException e){
            System.out.println("输入异常");
        }catch (ArithmeticException e){
            System.out.println("发生了除0异常");
        }catch (Exception e){

            System.out.println(e.getMessage());

        }//catch (Exception e)只能放在catch最后一句
        finally{

            System.out.println("异常解决完成");

        };



    }
    static  int num(int a,int b){
        int c=0;
        c=a/b;
        System.out.println("输出的结果"+ c);
        return c;
    }

/*    static int num(int a, int b){
        int c=0;
        if(b==0){
            System.out.println("被除数为0，式子不正确！");
        }
          if(b!=0)  {
              c=a/b;
              System.out.println("a / b = " + c +" ");
          }

         return c;

    }*/
}
